package com.baor.controller;

import com.baor.domain.DeviceInfo;
import com.baor.util.R;
import com.baor.domain.Article;
import com.baor.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping(value = "/news")
public class ArticeController {
  @Autowired
    private ArticleService  articleService;
  @RequestMapping(value = "/kaishi")
    public R kaishi(){
      List<Article>jg = articleService.abc();
      return R.ok(jg);
  }

  @RequestMapping(value = "/sx")
  public R sx(){

    return (articleService.sx());
  }

  @PostMapping("/insert")

  public R insertSomething(@RequestPart("article") Article article,
                           @RequestPart(value = "imageFiles", required = false) MultipartFile[] imageFiles) {
    boolean row = articleService.insert(article, imageFiles);
    if(row ){
      return R.ok();
    } else {
   return R.er("失败");
    }
  }


  @RequestMapping(value = "/sosuo")
  public R find(@RequestParam(name = "serch", required = false) String key){
    List<Article> articles=articleService.find(key);
    return (R.ok(articles));
  }
}
